#ifndef BUILDTIME_H_
#define BUILDTIME_H_

#include <e32std.h>
_LIT(KTimeDelimiter,".");

class CBuildTime : public CBase
{
public:
	
	static CBuildTime* CBuildTime::NewL()
	{
		CBuildTime* buildT = new CBuildTime();
		//buildT->ConstructL();
		return buildT;
	}
	
	void setStartTime()
	{
		TTime aTime;
		aTime.HomeTime();
		iTimeStarted = aTime;
	}
	
	void calcTime()
	{
		TTime aTime;
		aTime.HomeTime();
		iTimeFinished = aTime;
		
		iBuildTime.Delete(0,100);
		
		//debug
		//TBuf16<100> timeString;
		
		//_LIT(KTimeString1,"%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B  ");
		//iTimeStarted.FormatL(timeString, KTimeString1);
		
		//iBuildTime.Append(timeString);
		//iTimeFinished.FormatL(timeString, KTimeString1);
		//iBuildTime.Append(timeString);
		
		TInt SIntErr = 0;
		SIntErr = aTime.SecondsFrom(iTimeStarted, iTimeIntervalS);
		
		TInt SInt;
		SInt = iTimeIntervalS.Int();
		
		iTimeIntervalMS = 0;
		iTimeIntervalMS = aTime.MicroSecondsFrom(iTimeStarted);
		TInt64 MSInt64;
		MSInt64 = iTimeIntervalMS.Int64();
		TInt MSInt = I64INT(MSInt64);
		
		countTime(MSInt, SInt);
		
		if ( SInt > 0 )
		{
			MSInt = ( MSInt - (SInt * 1000000));
		}
		
		// output to TBuf
		iBuildTime.AppendNum(SInt);
		iBuildTime.Append(KTimeDelimiter);
		iBuildTime.AppendNumFixedWidth(MSInt, EDecimal, 6);
	}
	
	void countTime(TInt MSInt, TInt SInt)
	{
		if ( SInt > 0 )
		{
			MSInt = ( MSInt - (SInt * 1000000));
		}		
		
		MSTotalInt += MSInt;
		STotalInt += SInt;
		
		iTotalBuildTime.Delete(0,100);
		iTotalBuildTime.AppendNumFixedWidth(STotalInt, EDecimal, 4);
		iTotalBuildTime.Append(KTimeDelimiter);
		iTotalBuildTime.AppendNumFixedWidth(MSTotalInt, EDecimal, 6);
	}
	
	TBuf8<100> iBuildTime;
	TBuf8<100> iTotalBuildTime;
	
private:

	TInt MSTotalInt;
	TInt STotalInt;

	TTimeIntervalMicroSeconds iTimeIntervalMS;
	TTimeIntervalSeconds 	  iTimeIntervalS;
	
	TTime iTimeStarted;
	TTime iTimeFinished;
};

#endif /*BUILDTIME_H_*/
